import Mock from 'mockjs'
import url from 'url'
const Random = Mock.Random
import {compare} from "../../utils/compare";

//查询指定日期区间的数据
const queryMsgFromList = (list,start_date,end_date) =>{
    var newList = []

    for(var i =0;i<list.length;i++){
        if(compare(list[i].time,start_date)&&!compare(list[i].time,end_date)){

            var p = {time: list[i].time, name: list[i].name, data: list[i].data}

            newList.push(p);
        }
    }
    return newList
}

//负载趋势表格随机数据
const {LoadTrend_dataForm_List} = Mock.mock({
    'LoadTrend_dataForm_List|50-60': [
        {
            time: '@date(yyyy-MM-dd hh:mm:ss)',
            'name': '用电量',
            data: Random.float(6200000, 9999999, 0, 2),
        }
    ]
})

//电流趋势表格随机数据
const {CurrentTrend_dataForm_List} = Mock.mock({
    'CurrentTrend_dataForm_List|40-60': [
        {
            time: '@date(yyyy-MM-dd hh:mm:ss)',
            'name': '电流量',
            data: Random.float(6200000, 9999999, 0, 2),
        }
    ]
})

//电压趋势表格随机数据
const {VoltageTrend_dataForm_List} = Mock.mock({
    'VoltageTrend_dataForm_List|40-60': [
        {
            time: '@date(yyyy-MM-dd hh:mm:ss)',
            'name': '电压量',
            data: Random.float(6200000, 9999999, 0, 2),
        }
    ]
})

//水表耗水量表格随机数据
const {WaterConsumption_dataForm_List} = Mock.mock({
    'WaterConsumption_dataForm_List|40-60': [
        {
            time: '@date(yyyy-MM-dd hh:mm:ss)',
            'name': '用水量',
            data: Random.float(6200000, 9999999, 0, 2),
        }
    ]
})

//有功功率表格随机数据
const {ActivePower_dataForm_List} = Mock.mock({
    'ActivePower_dataForm_List|40-60': [
        {
            time: '@date(yyyy-MM-dd hh:mm:ss)',
            'name': '做功率',
            data: Random.float(6200000, 9999999, 0, 2),
        }
    ]
})






//负载趋势表格数据
Mock.mock('/api/module3/LoadTrend_dataForm','get',()=>{
    return {
        status: 200,
        message: '获取负载趋势信息成功',
        list: LoadTrend_dataForm_List,
    }
})

//电流趋势表格数据
Mock.mock('/api/module3/CurrentTrend_dataForm','get',()=>{
    return {
        status: 200,
        message: '获取负载趋势信息成功',
        list: CurrentTrend_dataForm_List,
    }
})

//电压趋势表格数据
Mock.mock('/api/module3/VoltageTrend_dataForm','get',()=>{
    return {
        status: 200,
        message: '获取负载趋势信息成功',
        list: VoltageTrend_dataForm_List,
    }
})

//电压趋势表格数据
Mock.mock('/api/module3/WaterConsumption_dataForm','get',()=>{
    return {
        status: 200,
        message: '获取负载趋势信息成功',
        list: WaterConsumption_dataForm_List,
    }
})

//用功功率表格数据
Mock.mock('/api/module3/ActivePower_dataForm','get',()=>{
    return {
        status: 200,
        message: '获取负载趋势信息成功',
        list: ActivePower_dataForm_List,
    }
})


//查询负载趋势图像组件中指定日期区间的数据
Mock.mock(/\api\/module3\/LoadTrend_dataForm_queryMsg/,'get',(options)=>{
    let {start_date,end_date} = url.parse(options.url,true).query;
    var newList = queryMsgFromList(LoadTrend_dataForm_List,start_date,end_date);
    return {
        status: 200,
        message: '获取负载趋势信息成功',
        list: newList,
    }
})

//查询电压趋势图像组件中指定日期区间的数据
Mock.mock(/\api\/module3\/VoltageTrend_dataForm_queryMsg/,'get',(options)=>{
    let {start_date,end_date} = url.parse(options.url,true).query;
    var newList = queryMsgFromList(VoltageTrend_dataForm_List,start_date,end_date);
    return {
        status: 200,
        message: '获取电压趋势信息成功',
        list: newList,
    }
})

//查询电流趋势图像组件中指定日期区间的数据
Mock.mock(/\api\/module3\/CurrentTrend_dataForm_queryMsg/,'get',(options)=>{
    let {start_date,end_date} = url.parse(options.url,true).query;
    var newList = queryMsgFromList(CurrentTrend_dataForm_List,start_date,end_date);
    return {
        status: 200,
        message: '获取电压趋势信息成功',
        list: newList,
    }
})

//查询有功功率图像组件中指定日期区间的数据
Mock.mock(/\api\/module3\/ActivePower_dataForm_queryMsg/,'get',(options)=>{
    let {start_date,end_date} = url.parse(options.url,true).query;
    var newList = queryMsgFromList(ActivePower_dataForm_List,start_date,end_date);
    return {
        status: 200,
        message: '获取电压趋势信息成功',
        list: newList,
    }
})

//查询水表耗水量图像组件中指定日期区间的数据
Mock.mock(/\api\/module3\/WaterConsumption_dataForm_queryMsg/,'get',(options)=>{
    let {start_date,end_date} = url.parse(options.url,true).query;
    var newList = queryMsgFromList(WaterConsumption_dataForm_List,start_date,end_date);
    return {
        status: 200,
        message: '获取电压趋势信息成功',
        list: newList,
    }
})
